<template>
	<view class="content">
		<view class="publish-wrap">
			<view class="publish-type">
				<view>发布类型</view>
				<view class="uni-list">
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view class="uni-input">{{array[index]}}</view>
					</picker>
				</view>
			</view>
			<view class="deal-content">
				<view class="commflex_">
					<!-- <view  style="font-weight: 600;">35个</view> -->
					<input type="text" placeholder="请输入交易数量" data-name="num" @input="inputBlur">
					<view>交易数量</view>
				</view>
			<!-- 	<view class="commflex_">
					<input type="text" placeholder="请输入单价" data-name="price" @input="inputBlur">
					<view>单价</view>
				</view> -->
				<view class="commflex_">
					<!-- <view style="font-weight: 600;">￥3580</view> -->
					<input type="password" placeholder="请输入交易密码" data-name="payPwd" @input="inputBlur">
					<view>交易密码</view>
				</view>
				<view style="padding: 10px;color: #ff6600;">
					<view class="font-size:14px">{{sxf}}</view>
				</view>
			</view>
			<view class="paychecktype">
				<view class="title">
					<text class="circle"></text>
					<view>付款方式</view>
				</view>
				<view class="changetype">
					<radio-group @change="radioChange">
						<view class="typeBox">
							<view class="wx">
								<radio :value="1+''" color="#ee5b25" :checked="paychecktype == 1" />微信
							</view>
							<view class="alipay">
								<radio :value="2+''" color="#ee5b25" :checked="paychecktype == 2" />支付宝
							</view>
						</view>
					</radio-group>
				</view>
			</view>
		</view>
		<view class="immediately" @click="toadd">
			立刻发布
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				payPwd: '',
				num: '',
				price: '',
				array: ['请选择类型', '立刻卖出', '立刻买入'],
				index: 0,
				paychecktype: 1,
				id: '',
				sxf: ''
			}
		},
		onLoad() {
			this.immediately()
			this.getconfig()
		},
		methods: {
			radioChange(e) {
				this.paychecktype = e.detail.value
				this.immediately(this.paychecktype)
			},
			getconfig() {
				let that = this;
				uni.request({
					url: 'https://www.ggshop1688.com/api/transaction/config',
					method: 'POST',
					header: {
						token: uni.getStorageSync('userInfo').token
					},
				}).then(res => {
					if (res[1].data.status == 1) {
						that.sxf = res[1].data.data[0].commission.description;
					}
				})
			},
			inputBlur(e) {
				let key = e.currentTarget.dataset.name;
				this[key] = e.detail.value
			},
			bindPickerChange(e) {
				this.index = e.target.value
			},
			immediately() {
				let that = this;
				uni.request({
					url: 'https://www.ggshop1688.com/api/transaction/get_payinfo',
					data: {
						pay_type: this.paychecktype,
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('userInfo').token
					},
				}).then(res => {
					if (res[1].data.status == 1) {
						if (res[1].data.data.length == 0) {
							that.$api.msg('还没有添加收款码请先添加');
							setTimeout(() => {
								uni.navigateTo({
									url: '../uploadimg/uploadimg?id=' + that.id
								})
							}, 500)
						}
					}
					if (res[1].data.status == -1) {
						if (data[1].data.msg == '还没有添加微信收款码请先添加' || data[1].data.msg == '还没有添加支付宝收款码请先添加') {
							that.$api.msg(res[1].data.msg)
							setTimeout(() => {
								uni.navigateTo({
									url: '../uploadimg/uploadimg?id=' + that.id
								})
							}, 500)
						}
					}
				})

			},
			toadd() {

				let that = this;
				if (!this.payPwd) {
					this.$api.msg('请输入支付密码')
					return;
				}
				if (this.index == 0) {
					this.$api.msg('请选择类型')
					return;
				}
				uni.request({
					url: 'https://www.ggshop1688.com/api/transaction/out_in_come',
					data: {
						payPwd: this.payPwd,
						num: this.num,
						pay_type: this.paychecktype,
						price: this.price,
						type: this.index
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('userInfo').token
					},
				}).then(data => {
					console.log(data[1].data)
					if (data[1].data.status == -1) {
						that.$api.msg(data[1].data.msg)
						if (data[1].data.msg == '还没有添加微信收款码请先添加' || data[1].data.msg == '还没有添加支付宝收款码请先添加') {
							setTimeout(() => {
								uni.navigateTo({
									url: '../uploadimg/uploadimg?id=' + that.id
								})
							}, 500)

						}
					} else {
						that.$api.msg(data[1].data.msg)
						uni.navigateBack()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.publish-wrap {
		font-size: 24upx;
		padding: 20upx;

		.publish-type {
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #f2f2f2;
			padding: 20upx;
		}

		.deal-content {
			.commflex_ {
				display: flex;
				justify-content: space-between;
				padding: 20upx;
				border-bottom: 1px solid #f2f2f2;
			}
		}

		.paychecktype {
			padding: 20upx 20upx 40upx 20upx;
			box-shadow: 0px 0px 6px 2px #f2f2f2;
			margin-top: 20px;
			border-radius: 20upx;

			.title {
				padding: 20upx 0px;
				display: flex;
				align-items: center;

				.circle {
					width: 14upx;
					height: 14upx;
					background-color: #f90202ab;
					display: inline-block;
					border-radius: 50%;
					margin-right: 10upx;
				}
			}

			.changetype {
				.typeBox {
					display: flex;
					align-items: center;

					.wx {
						display: flex;
						align-items: center;
						margin-right: 30upx;

						.uni-radio-wrapper {
							.uni-radio-input {
								width: 30upx;
								height: 30upx;
								box-sizing: border-box;
							}
						}
					}

					.alipay {
						display: flex;
						align-items: center;

						.uni-radio-input {

							width: 30upx;
							height: 30upx;
							box-sizing: border-box;
						}
					}
				}
			}
		}
	}

	.immediately {
		margin: 35px auto;
		background-color: #ff6600;
		color: #fff;
		height: 70upx;
		line-height: 70upx;
		text-align: center;
		width: 60%;
		-webkit-border-radius: 5px;
		border-radius: 5px;
		font-size: 12px;
	}
</style>
